//
//  WYCSetPassController.m
//  51信用卡
//
//  Created by 中企互联 on 2017/11/3.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "WYCZhifusetController.h"
#import "UIButton+CountDown.h"
#import "RSAUtil.h"
#import "WYCLoginController.h"

@interface WYCZhifusetController ()
/** 账号*/
@property(nonatomic,strong)UITextField * usertexfield;

/** 验证码*/
@property(nonatomic,strong)UITextField * codefield;

/** 密码*/
@property(nonatomic,strong)UITextField * passtexfield;

/** 再次输入密码*/
@property(nonatomic,strong)UITextField * Zpasstexfield;
@end

@implementation WYCZhifusetController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改支付密码";
    CGFloat tableviewY = CGRectGetMaxY(self.navigationController.navigationBar.frame);
    
    self.usertexfield = [[UITextField alloc] init];
    self.usertexfield.frame = CGRectMake(40 * px, tableviewY + 40 * px, ScreenWidth - 80 * px, 120 * px);
    //    usertexfield.backgroundColor = [UIColor redColor];
    self.usertexfield.keyboardType = UIKeyboardTypeNumberPad;
    self.usertexfield.placeholder = @"请输入手机号";
    [self.view addSubview:self.usertexfield];
    
    //手机提示线
    UIView * lineView = [[UIView alloc] init];
    lineView.frame = CGRectMake(self.usertexfield.x, CGRectGetMaxY(self.usertexfield.frame) + 5 * px, self.usertexfield.width, 1);
    lineView.backgroundColor = WYCGlobalBg;
    [self.view addSubview:lineView];
    
    
    ////////////////
    /////密码输入框/////
    ///////////////
    
    
    
    
    self.codefield = [[UITextField alloc] init];
    self.codefield.frame = CGRectMake(self.usertexfield.x, CGRectGetMaxY(lineView.frame) + 80 * px, self.usertexfield.width / 2, self.usertexfield.height);
    self.codefield.placeholder = @"验证码";
    [self.view addSubview:self.codefield];
    
    //手机提示线
    UIView * passlineView = [[UIView alloc] init];
    passlineView.frame = CGRectMake(self.codefield.x, CGRectGetMaxY(self.codefield.frame) + 5 * px, lineView.width, 1);
    passlineView.backgroundColor = WYCGlobalBg;
    [self.view addSubview:passlineView];
    
    //获取验证码
    UIButton * codebutton = [[UIButton alloc] init];
    codebutton.frame = CGRectMake(ScreenWidth - 350 * px, self.codefield.y, 300 * px, self.codefield.height);
    [codebutton setTitleColor:WYCMain forState:UIControlStateNormal];
    codebutton.titleLabel.font = [UIFont systemFontOfSize:MiddleFont];
    [codebutton setTitle:@"获取验证码" forState:UIControlStateNormal];
    [codebutton addTarget:self action:@selector(countDownBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:codebutton];
    
    
    
    //注册按钮
    UIButton * loginButton = [[UIButton alloc] init];
    loginButton.frame = CGRectMake(self.usertexfield.x, CGRectGetMaxY(codebutton.frame) + 300 * px, self.usertexfield.width, 150 * px);
    loginButton.backgroundColor = WYCMain;
    loginButton.layer.cornerRadius = 3;
    [loginButton setTitle:@"下一步" forState:UIControlStateNormal];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:72 * px];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(RegisterClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];
}


#pragma make ------->>
- (void)RegisterClick{
    WYCLog(@"---------------->");
    //手机号判断是否为空
    if(self.usertexfield.text.length == 0)
    {
        [self showToast:@"手机号不能为空"];
        return;
    }
    //验证码判断是否为空
    if(self.codefield.text.length == 0)
    {
        [self showToast:@"请输入验证码"];
        return;
    }
    
    NSString * httpsStr = [NSString stringWithFormat:@"%@mobile=%@&type=%@",Rcode,self.usertexfield.text,Ucodekey];
    
    [HttpTool POST:httpsStr params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
            [self showToast:msgStr];
            
        }else{
            
            [self showToast:msgStr];
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}

#pragma make -------->>获取验证码
- (void)countDownBtnAction:(UIButton *)button
{
    WYCLog(@"----------%@",self.usertexfield.text);
    WYCLogFunc;
    if (self.usertexfield.text.length == 0) {
        
        NSString * showStr = @"手机号不能为空";
        [self showToast:showStr];
        return;
    }else{
        [button startWithTime:59 title:@"点击重新获取" countDownTitle:@"s后重新获取" mainColor:[UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0] countColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
        NSString * httpsStr = [NSString stringWithFormat:@"%@mobile=%@&type=%@",Rcode,self.usertexfield.text,Ucodekey];
        
        [HttpTool POST:httpsStr params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            
            if ([[responseObject objectForKey:@"code"] intValue] == 0) {
                
                [self showToast:msgStr];
                
                
            }else{
                
                [self showToast:msgStr];
            }
            
        } fail:^(NSURLSessionDataTask *task, NSError *error) {
            
        }];
        
    }
}


//键盘回收
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.usertexfield resignFirstResponder];
    [self.passtexfield resignFirstResponder];
    [self.codefield resignFirstResponder];
    [self.Zpasstexfield resignFirstResponder];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    UIView * NavView = [[UIView alloc] init];
    NavView.frame = CGRectMake(0, 0, ScreenWidth, NavHeight);
    NavView.backgroundColor = WYCmainColor;
    [self.view addSubview:NavView];
    
    
    
    CALayer *bottomLineLayer = [[CALayer alloc] init];
    bottomLineLayer.frame = CGRectMake(0, NavView.bounds.size.height - 0.5, NavView.bounds.size.width, 0.5);
    bottomLineLayer.backgroundColor = WYCmainColor.CGColor;
    [NavView.layer addSublayer:bottomLineLayer];
    
    
    
    
    
    //返回按钮
    UIButton *  fanhuibutton = [[UIButton alloc] init];
    [fanhuibutton setImage:[UIImage imageNamed:@"Nav_back"] forState:UIControlStateNormal];
    [fanhuibutton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    fanhuibutton.frame = CGRectMake(30 * px, titleY, 66 * px , 66 * px);
    [NavView addSubview:fanhuibutton];
    
    
    UILabel * NavRigsterLabel = [[UILabel alloc] init];
    NavRigsterLabel.frame = CGRectMake(0, titleY, NavView.width, 68 * px);
    NavRigsterLabel.textColor = [UIColor whiteColor];
    NavRigsterLabel.font = [UIFont boldSystemFontOfSize:BigFont];
    NavRigsterLabel.textAlignment = NSTextAlignmentCenter;
    NavRigsterLabel.text = @"修改支付密码";
    [NavView addSubview:NavRigsterLabel];
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end

